﻿using System;
using Csla.Xaml;
using Accounting.Library;
using System.ComponentModel;
using Utility;
using Accounting.Library.Utility;



namespace csla4Skeleton.UI.SL.NghiepVu.TinhGiaThanh.GT_TinhGiaThanh
{
    public class GT_TinhGiaThanh_ViewModel : ViewModel<Accounting.Library.GT_TinhGiaThanh>
    {
        #region Event Declare
        public delegate void ChildList_AddedNew_EventHandler(object sender, ChildListAddedNewArgs e);
       
        public event ChildList_AddedNew_EventHandler ChildList_AddedNew;

        public event EventHandler CountChanged;
        public event EventHandler KyGiaThanhIdChanged;
        public event EventHandler LoadCompleted;
        public event EventHandler Saved;
        public event EventHandler Canceled;
        
        #endregion

        #region Refresh Model
        public GT_TinhGiaThanh_ViewModel()
        {
            BeginRefresh("NewGT_TinhGiaThanh");
            
        }

        public GT_TinhGiaThanh_ViewModel(string mode)
        {
            if (mode.Equals(BusinessConfiguration.Configuration.ChildWindow))
            {
                this.BeginRefresh("NewGT_TinhGiaThanh");
            }
           
        }
        public GT_TinhGiaThanh_ViewModel(int Khoa)
        {
            BeginRefresh("GetGT_TinhGiaThanh", Khoa);
           
        }

        public void NewGT_TinhGiaThanhViewModel()
        {
            BeginRefresh("NewGT_TinhGiaThanh");
            
        }

        public void GetGT_TinhGiaThanhViewModel(int Khoa)
        {
            BeginRefresh("GetGT_TinhGiaThanh", Khoa);
        }

       
        public void SaveAndNew()
        {
            BeginSave();
            NewGT_TinhGiaThanhViewModel();
        }
        protected override void OnRefreshed()
        {
            base.OnRefreshed();
            if (Model != null)
            {
                Model.GT_TinhGiaThanh_ChiTiets.AddedNew += new EventHandler<Csla.Core.AddedNewEventArgs<GT_TinhGiaThanh_ChiTietChild>>(GT_TinhGiaThanh_ChiTiets_AddedNew);

                Model.BusyEvent += new EventHandler<IsBusyEventArgs>(DoChangingBusy);
                Model.KyGiaThanhIdChanged += new EventHandler(OnKyGiaThanhIdChanged);
                Model.CountChanged += new EventHandler(OnCountChanged);
                if (LoadCompleted != null)
                {
                    LoadCompleted(this, new EventArgs());
                }
            }
        }
        #endregion
        
        #region Add GT_TinhGiaThanh Details Item
        public void AddGT_TinhGiaThanh_ChiTietItem()
        {
            Model.GT_TinhGiaThanh_ChiTiets.AddNewItem(Model.Khoa);
        }


        void GT_TinhGiaThanh_ChiTiets_AddedNew(object sender, Csla.Core.AddedNewEventArgs<GT_TinhGiaThanh_ChiTietChild> e)
        {
            OnChildList_AddedNew(sender, new ChildListAddedNewArgs("GT_TinhGiaThanh_ChiTiets"));
        }      

        protected virtual void OnChildList_AddedNew(object sender, ChildListAddedNewArgs e)
        {
            if (ChildList_AddedNew != null)
            {
                //Invokes the delegates.
                ChildList_AddedNew(sender, e);
            }
        }



        public void OnKyGiaThanhIdChanged(object sender, EventArgs e)
        {
            if (KyGiaThanhIdChanged != null)
            {
                KyGiaThanhIdChanged(sender, e);
            }

        }
        public void OnCountChanged(object sender, EventArgs e)
        {
            if (CountChanged != null)
            {
                CountChanged(sender, e);
            }

        }
        public void DoChangingBusy(object sender, IsBusyEventArgs e)
        {
            IsBusy = e.Busy;
        }
        public void DoChangingBusy(bool busy)
        {
            IsBusy = busy;
        }
        

        protected override void OnSaved()
        {
            base.OnSaved();
            if (Saved != null)
            {
                Saved(this, EventArgs.Empty);
            }
           
        }

        protected override void DoCancel()
        {
            base.DoCancel();
            if (Canceled != null)
            {
                Canceled(this, EventArgs.Empty);
            }
            
        }

      
        #endregion

        #region Delete GT_TinhGiaThanh Details Item

        public void DeleteGT_TinhGiaThanh_ChiTietItem(int Index)
        {
            Model.GT_TinhGiaThanh_ChiTiets.DeleteItem(Index);
        }

        

        #endregion
       
    }
}
